package train48days;

import java.util.Scanner;

public class 扑克牌大小 {
    public static void main(String[] args) {
        String poker = "345678910JQKA2jokerJOKER";
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String s = sc.nextLine();
            if (s.contains("joker JOKER")){
                System.out.println("joker JOKER");
            }else {
                String[] str = s.split("-");
                String[] left = str[0].split(" ");
                String[] right = str[1].split(" ");
                if (left.length==4&&right.length!=4){
                    System.out.println(str[0]);
                }else if (left.length!=4&&right.length==4){
                    System.out.println(str[1]);
                }else if (left.length==right.length){
                    if (left[0].equals("JOKER")||right[0].equals("JOKER")){
                        System.out.println("JOKER");
                    }else if (left[0].equals("joker")&&!right[0].equals("JOKER")){
                        System.out.println("joker");
                    } else if (right[0].equals("joker")&&!left[0].equals("JOKER")) {
                        System.out.println("joker");
                    } else if (poker.indexOf(left[0])>poker.indexOf(right[0])) {
                        System.out.println(str[0]);
                    }else if (poker.indexOf(left[0])<poker.indexOf(right[0])){
                        System.out.println(str[1]);
                    }
                }else {
                    System.out.println("ERROR");
                }
            }
        }
    }
}
